Skip to content

Conversation

@savanto
Copy link
Contributor

@savanto savanto commented Dec 27, 2025

According to the docstring for append:

(typ, [data]) = <instance>.append(mailbox, flags, date_time, message)

Python v3.0
Python v3.14

Further corroborated that this is a tuple because append returns the result of self._simple_command(...), which returns the result of self._command_complete(...), which returns typ, data.

From something like this

with IMAP4_SSL(...) as imap:
    imap.login(...)
    (status, data) = imap.append(...)

I'm getting a Mypy (v1.17.1) type error:

error: Unpacking a string is disallowed  [misc]

when in practice unpacking the tuple works just fine.

According to the docstring for append:
```
(typ, [data]) = <instance>.append(mailbox, flags, date_time, message)
```
[v3.0](https://github.com/python/cpython/blob/v3.0/Lib/imaplib.py#L313)
[v3.14](https://github.com/python/cpython/blob/v3.14.0/Lib/imaplib.py#L483)

Further corroborated that this is a tuple of some sort because append
returns the result of `self._simple_command(...)`, which returns the
result of `self._command_complete(...)`, which returns `typ, data`.
@github-actions

This comment has been minimized.

@savanto savanto marked this pull request as ready for review December 27, 2025 21:00
Copy link
Contributor

@donbarbos donbarbos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Only one nit

Co-authored-by: Semyon Moroz <donbarbos@proton.me>
@github-actions
Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@srittau srittau merged commit 1662831 into python:main Dec 28, 2025
63 checks passed
def recent(self) -> _CommandResults: ...
def response(self, code: str) -> _CommandResults: ...
def append(self, mailbox: str, flags: str, date_time: str, message: ReadableBuffer) -> str: ...
def append(self, mailbox: str, flags: str, date_time: str, message: ReadableBuffer) -> tuple[str, _list[bytes]]: ...

This comment was marked as outdated.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in #15187

@savanto savanto deleted the imaplib-append-return branch December 28, 2025 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants